package com.chenxi.vhr.controller.salary;

import com.chenxi.vhr.bean.VhrSalary;
import com.chenxi.vhr.bean.common.NasDeleteListForm;
import com.chenxi.vhr.bean.common.Result;
import com.chenxi.vhr.service.VhrSalaryService;
import com.chenxi.vhr.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工資账套管理
 * @author : zhangchenxi
 * @create : 2022-02-13
 **/
@RestController
@RequestMapping("/salary/sob")
public class SalarySobController {

    @Autowired
    VhrSalaryService salaryService;

    @GetMapping
    public Result list() {
        List<VhrSalary> list = salaryService.list();
        return Result.ok("查询成功", list);
    }

    @PostMapping
    public Result add(@RequestBody VhrSalary entity) {
        entity.setCreateDate(DateUtil.getNowDate());
        boolean save = salaryService.save(entity);
        return save ? Result.ok("添加成功！"): Result.error("添加失败！");
    }

    @PutMapping
    public Result update(@RequestBody VhrSalary entity) {
        boolean update = salaryService.saveOrUpdate(entity);
        return update ? Result.ok("修改成功！"): Result.error("修改失败！");
    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id) {
        return salaryService.removeById(id) ? Result.ok("删除成功！"): Result.error("删除失败！");
    }

    @DeleteMapping("/batch")
    public Result batchDelete(@RequestBody NasDeleteListForm form) {
        return salaryService.removeByIds(form.getIdList()) ? Result.ok("批量删除成功！"): Result.error("批量删除失败！");
    }


}
